//
//  ZDDVisitorView.swift
//  小蜗牛_新浪微博
//
//  Created by 周冬冬 on 16/6/25.
//  Copyright © 2016年 我的mac. All rights reserved.
//

import UIKit
import SnapKit

class ZDDVisitorView: UIView {
    // button按钮点击闭包
    var closure:(()->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   private func setUI(){
    
    
        backgroundColor = RBG(237,green: 237,blue: 237)
    //添加控件
    addSubview(feedImageView)
    addSubview(maskImageView)
    addSubview(iconImageView)
    addSubview(messageLabel)
    addSubview(loginButton)
    addSubview(registerButton)
    //添加约束
    //圆圈
    feedImageView.snp_makeConstraints { (make) -> Void in
        make.center.equalTo(self)
    }
    //遮罩
    maskImageView.snp_makeConstraints { (make) -> Void in
        make.center.equalTo(self)
    }
    //房子
    iconImageView.snp_makeConstraints { (make) -> Void in
        make.center.equalTo(self)
    }
    //文字
    messageLabel.snp_makeConstraints { (make) -> Void in
        make.width.equalTo(224)
        make.height.equalTo(36)
        make.top.equalTo(maskImageView.snp_bottom).offset(16)
        make.centerX.equalTo(maskImageView)
    }
    //登录
    loginButton.snp_makeConstraints { (make) -> Void in
        make.leading.equalTo(messageLabel)
        make.size.equalTo(CGSize(width: 100, height: 36))
        make.top.equalTo(messageLabel.snp_bottom).offset(16)
        
    }
    //注册
    registerButton.snp_makeConstraints { (make) -> Void in
        make.trailing.equalTo(messageLabel)
        make.size.equalTo(CGSize(width: 100, height: 36))
        make.top.equalTo(messageLabel.snp_bottom).offset(16)
        
    }
//    feedImageView.translatesAutoresizingMaskIntoConstraints = false
//    
//    addConstraint(NSLayoutConstraint(item: feedImageView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
//    addConstraint(NSLayoutConstraint(item: feedImageView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
    
    }
    
    //设置动画
    func setupAnim(){
    
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.duration = 10
        
        anim.toValue = M_PI * 2
        
        //动画次数
        anim.repeatCount = MAXFLOAT
        
        anim.removedOnCompletion = false
        
        //添加动画
        feedImageView.layer.addAnimation(anim, forKey: nil)
    
    
    
    }
    func setupVisitorViewInfor(imageName:String?,title:String?){
    
        if let img = imageName,let tit = title{
        
            iconImageView.image = UIImage(named: img)
            messageLabel.text = tit
            
            feedImageView.hidden = true
         
        
        }else{
        
        //是首页
            setupAnim()
        
        }
    
    
    }
    @objc private func buttonClick(){
    
    closure?()
    
    }
     //  MARK: - 懒加载控件
    //圆圈
   private lazy var feedImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    
    //遮罩
    
    private lazy var maskImageView:UIImageView = UIImageView(imageName:"visitordiscover_feed_mask_smallicon")
    
    //房子
    private lazy var iconImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    
    //文字
    private lazy var messageLabel:UILabel = {
    
        let zddLabel = UILabel()
        zddLabel.textColor = ThemeColor
        zddLabel.text = "关注一些人,回这里看看有什么惊喜关注一些人,回这里看看有什么惊喜"
        zddLabel.numberOfLines = 0
        
        zddLabel.font = UIFont.systemFontOfSize(14)
        zddLabel.textAlignment = .Center
        return zddLabel
    
    
    }()
    
    //登录
    private lazy var loginButton:UIButton = {
    let button = UIButton()
        button.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("登录", forState: UIControlState.Normal)
        button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        return button
    
    }()
    //注册
    private lazy var registerButton:UIButton = {
        let button = UIButton()
        // 添加事件
    button.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
    button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("注册", forState: UIControlState.Normal)
        button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        return button
        
    }()
    
}























